#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# ======================================================
# @File:      : test3
# @Author     : forward_huan
# @Date       : 2024/11/16 21:08
# @Desc       :
# ======================================================
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if len(s) <= 1:
            return len(s)
        max_len, data, start = 0, {}, 0
        for i, item in enumerate(s):
            if item in data and data[item] >= start:
                max_len = max(max_len, i - start)
                start = data[item] + 1
            data[item] = i
        max_len = max(max_len, len(s) - start)
        return max_len



# print(Solution().lengthOfLongestSubstring(s="abcabcbb"))
# print(Solution().lengthOfLongestSubstring(s="bbbbb"))
# print(Solution().lengthOfLongestSubstring(s="pwwkew"))
# print(Solution().lengthOfLongestSubstring(s="  "))
# print(Solution().lengthOfLongestSubstring(s="au"))
print(Solution().lengthOfLongestSubstring(s="ohvhjdml"))
